clear
close all
clc

fntsize=14;
w=500;
h=w*2/(1+sqrt(5));
col=[0;0.5;0.8;1]*ones(1,3);
se=1.96;
printyes=1;

x_ASM=(-4:1:5)';
x_CMF=(0:1:1)';

%% Load data and save variable names
[data,labels]=xlsread('DataForFiguresTables.xlsx','VShape_firms','B1:K15');
[M,N]=size(labels);

for i=1:2:N-1
    assignin('base',strcat(labels{1,i},'_est'),data(1,i:i+1)');
    assignin('base',strcat(labels{1,i},'_se') ,data(2,i:i+1)');

    assignin('base',strcat(labels{1,i},'_1970s_est'),data(5,i:i+1)');
    assignin('base',strcat(labels{1,i},'_1970s_se') ,data(6,i:i+1)');

    assignin('base',strcat(labels{1,i},'_2000s_est'),data(9 ,i:i+1)');
    assignin('base',strcat(labels{1,i},'_2000s_se') ,data(10,i:i+1)');
end

%% Plot Figure C.3: VShape dynamics of labor shares of LL firms
figure('position',[0 0 w h]);
hold on
a=bar(x_CMF,dLS_est,0.4);
errorbar(x_CMF,dLS_est,se*dLS_se,'.','linewidth',1,'color','k','marker','o','markerfacecolor','k')
a(1).FaceColor = col(2,:);
ax = gca;ax.YGrid = 'on';
set(gca,'xlim',[-0.5 1.5],'ylim',[-0.19 0.005],'ytick',(-0.16:0.04:0),'xtick',x_CMF,'ticklabelinterpreter','latex');   % changed the ylim and ytick
set(gca,'XTickLabel',{'$t-5\;$ to $\;t$' '$t-5\;$ to $\;t+5$'},'fontsize',fntsize)
xlabel('Cumulative change from ...','interpreter','latex','fontsize',fntsize)
title('$\Delta\lambda_t^{LL}-\Delta\lambda_t^{Non-LL}$ of $LL$ firms','fontsize',fntsize,'interpreter','latex');
% lgnd=legend([a(1)],{'$LL$ firms'},'fontsize',fntsize,'location','se','interpreter','latex');
% set(lgnd,'color','white');
if printyes==1
    print('../Figures/Fig_VShape_LSfirm_cum.eps','-depsc')
end

%% Plot Figure C.4: VShape dynamics of labor share components of LL firms
[bar_pos,bar_neg,x_pos,x_neg]=barstacked([d_log_W_est d_log_L_est -d_log_VA_est]);
figure('position',[0 0 w h]);
b1  =bar((0:1)'*ones(1,3),bar_pos,0.5,'stacked');
hold on
b2  =bar((0:1)'*ones(1,3),bar_neg,0.5,'stacked');
errorbar([0 -0.1 0.1;1 0.9 1.1],x_pos,se*[d_log_W_se d_log_L_se d_log_VA_se],'.','linewidth',1,'color','k','marker','o','markerfacecolor','k')
errorbar([0 -0.1 0.1;1 0.9 1.1],x_neg,se*[d_log_W_se d_log_L_se d_log_VA_se],'.','linewidth',1,'color','k','marker','o','markerfacecolor','k')
b1(1).FaceColor = col(4,:);
b1(2).FaceColor = col(3,:);
b1(3).FaceColor = col(2,:);
b2(1).FaceColor = col(4,:);
b2(2).FaceColor = col(3,:);
b2(3).FaceColor = col(2,:);
set(gca,'xlim',[-0.5 1.5],'xtick',x_CMF,'ticklabelinterpreter','latex','XTickLabel',{'$t-5\;$ to $\;t$' '$t-5\;$ to $\;t+5$'},'fontsize',fntsize)
ax = gca;
ax.YGrid = 'on';
xlabel('Cumulative change from ...','interpreter','latex','fontsize',fntsize)
title('Growth rate of components of $\Delta\log\lambda^{LL}$ of $LL$ firms','fontsize',fntsize,'interpreter','latex');
lgnd=legend([b1(2);b1(1);b1(3)],{'Labor $\Delta\log L^{LL}$';'Wages $\Delta\log W^{LL}$';'Value added $\Delta\log Y^{LL}$'},'fontsize',fntsize,'location','se','interpreter','latex');
set(lgnd,'color','white');
if printyes==1
    print('../Figures/Fig_VShape_WandVAandL_cum_firms_NEW.eps','-depsc')
end

%% Plot Figure C.5: VShape dynamics of labor shares of LL firms - 1970s vs. 2000s:
figure('position',[0 0 w h]);
hold on
a=bar(x_CMF,dLS_1970s_est,0.4);
errorbar([x_CMF],dLS_1970s_est,se*dLS_1970s_se,'.','linewidth',1,'color','k','marker','o','markerfacecolor','k')
a(1).FaceColor = col(2,:);
ax = gca;ax.YGrid = 'on';
set(gca,'xlim',[-0.5 1.5],'ylim',[-0.2 0.014],'ytick',(-0.2:0.04:0),'xtick',x_CMF,'ticklabelinterpreter','latex');   % changed the ylim and ytick
set(gca,'XTickLabel',{'$t-5\;$ to $\;t$' '$t-5\;$ to $\;t+5$'},'fontsize',fntsize)
xlabel('Cumulative change from ...','interpreter','latex','fontsize',fntsize)
title('$\Delta\lambda_t^{LL}-\Delta\lambda_t^{Non-LL}$ of $LL$ firms: 1970s','fontsize',fntsize,'interpreter','latex');
% lgnd=legend([a(1)],{'$LL$ firms'},'fontsize',fntsize,'location','se','interpreter','latex');
% set(lgnd,'color','white');
if printyes==1
    print('../Figures/Fig_VShape_LSfirm_cum1970s.eps','-depsc')
end

% 2000s
figure('position',[0 0 w h]);
hold on
a=bar(x_CMF,dLS_2000s_est,0.4);
errorbar(x_CMF,dLS_2000s_est,se*dLS_2000s_se,'.','linewidth',1,'color','k','marker','o','markerfacecolor','k')
a(1).FaceColor = col(2,:);
ax = gca;ax.YGrid = 'on';
set(gca,'xlim',[-0.5 1.5],'ylim',[-0.2 0.014],'ytick',(-0.2:0.04:0),'xtick',x_CMF,'ticklabelinterpreter','latex');   % changed the ylim and ytick
set(gca,'XTickLabel',{'$t-5\;$ to $\;t$' '$t-5\;$ to $\;t+5$'},'fontsize',fntsize)
xlabel('Cumulative change from ...','interpreter','latex','fontsize',fntsize)
title('$\Delta\lambda_t^{LL}-\Delta\lambda_t^{Non-LL}$ of $LL$ firms: 2000s','fontsize',fntsize,'interpreter','latex');
% lgnd=legend([a(1)],{'$LL$ firms'},'fontsize',fntsize,'location','se','interpreter','latex');
% set(lgnd,'color','white');
if printyes==1
    print('../Figures/Fig_VShape_LSfirm_cum2000s.eps','-depsc')
end

%% Plot Figure C.6
[bar_pos,bar_neg,x_pos,x_neg]=barstacked([d_log_W_1970s_est d_log_L_1970s_est -d_log_VA_1970s_est]);
figure('position',[0 0 w h]);
b1  =bar((0:1)'*ones(1,3),bar_pos,0.4,'stacked');
hold on
b2  =bar((0:1)'*ones(1,3),bar_neg,0.4,'stacked');
errorbar([0 -0.1 0.1;1 0.9 1.1],x_pos,se*[d_log_W_1970s_se d_log_L_1970s_se d_log_VA_1970s_se],'.','linewidth',1,'color','k','marker','o','markerfacecolor','k')
errorbar([0 -0.1 0.1;1 0.9 1.1],x_neg,se*[d_log_W_1970s_se d_log_L_1970s_se d_log_VA_1970s_se],'.','linewidth',1,'color','k','marker','o','markerfacecolor','k')
b1(1).FaceColor = col(4,:);
b1(2).FaceColor = col(3,:);
b1(3).FaceColor = col(2,:);
b2(1).FaceColor = col(4,:);
b2(2).FaceColor = col(3,:);
b2(3).FaceColor = col(2,:);
set(gca,'xlim',[-0.5 1.5],'ylim',[-0.8 0.28],'ytick',(-0.8:0.2:0.2),'xtick',x_CMF,'ticklabelinterpreter','latex','XTickLabel',{'$t-5\;$ to $\;t$' '$t-5\;$ to $\;t+5$'},'fontsize',fntsize)
ax = gca;
ax.YGrid = 'on';
xlabel('Cumulative change from ...','interpreter','latex','fontsize',fntsize)
title('Growth rates of components of $\Delta \log \lambda^{LL}$ for $LL$ firms: 1970s','fontsize',fntsize,'interpreter','latex');
lgnd=legend([b1(2);b1(1);b1(3)],{'Labor $\Delta\log L^{LL}$';'Wages $\Delta\log W^{LL}$';'Value added $\Delta\log Y^{LL}$'},'fontsize',fntsize,'location','se','interpreter','latex');
set(lgnd,'color','white');
if printyes==1
    print('../Figures/Fig_VShape_WandVAandL1970_Firms_cum.eps','-depsc')
end

[bar_pos,bar_neg,x_pos,x_neg]=barstacked([d_log_W_2000s_est d_log_L_2000s_est -d_log_VA_2000s_est]);
figure('position',[0 0 w h]);
b1  =bar((0:1)'*ones(1,3),bar_pos,0.4,'stacked');
hold on
b2  =bar((0:1)'*ones(1,3),bar_neg,0.4,'stacked');
errorbar([0 -0.1 0.1;1 0.9 1.1],x_pos,se*[d_log_W_2000s_se d_log_L_2000s_se d_log_VA_2000s_se],'.','linewidth',1,'color','k','marker','o','markerfacecolor','k')
errorbar([0 -0.1 0.1;1 0.9 1.1],x_neg,se*[d_log_W_2000s_se d_log_L_2000s_se d_log_VA_2000s_se],'.','linewidth',1,'color','k','marker','o','markerfacecolor','k')
b1(1).FaceColor = col(4,:);
b1(2).FaceColor = col(3,:);
b1(3).FaceColor = col(2,:);
b2(1).FaceColor = col(4,:);
b2(2).FaceColor = col(3,:);
b2(3).FaceColor = col(2,:);
set(gca,'xlim',[-0.5 1.5],'ylim',[-0.8 0.28],'ytick',(-0.8:0.2:0.2),'xtick',x_CMF,'ticklabelinterpreter','latex','XTickLabel',{'$t-5\;$ to $\;t$' '$t-5\;$ to $\;t+5$'},'fontsize',fntsize)
ax = gca;
ax.YGrid = 'on';
xlabel('Cumulative change from ...','interpreter','latex','fontsize',fntsize)
title('Growth rates of components of $\Delta \log \lambda^{LL}$ for $LL$ firms: 2000s','fontsize',fntsize,'interpreter','latex');
lgnd=legend([b1(2);b1(1);b1(3)],{'Labor $\Delta\log L^{LL}$';'Wages $\Delta\log W^{LL}$';'Value added $\Delta\log Y^{LL}$'},'fontsize',fntsize,'location','se','interpreter','latex');
set(lgnd,'color','white');
if printyes==1
    print('../Figures/Fig_VShape_WandVAandL2000_Firms_cum.eps','-depsc')
end


